<%--
  Created by IntelliJ IDEA.
  User: kurong
  Date: 2021/10/8
  Time: 16:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>树懒-欢迎登录</title>
    <link href="../css/login.css" rel="stylesheet">
</head>
<body>

<div class="w">
    <div id="logo">
        <a href="">
            <img src="../images/logo.png" width="170" height="60">
        </a>
        <b></b>
    </div>
    <a href="" class="q-link">
        <b></b>
        登录页面，调查问卷
    </a>
</div>

<div id="content">
    <div class="tips-wrapper">
        <div class="tips-inner">
            <div class="cont-wrapper">
                <i class="icon-tips"></i>
                <p>
                    依据《网络安全法》，为保障您的账户安全和正常使用，请尽快完成手机号验证！ 新版《树懒隐私政策》已上线，将更有利于保护您的个人隐私。
                </p>
            </div>
        </div>
    </div>
    <div class="login-wrap">
        <div class="w">
            <div class="login-form">
                <div class="tips-wrapper">
                    <div class="tips-inner">
                        <div class="cont-wrapper">
                            <i class="icon-tips"></i>
                            <p>
                                树懒不会以任何理由要求您转账汇款，谨防诈骗。
                            </p>
                        </div>
                    </div>
                </div>


                <div class="login-tab login-tab-l">
                    <a href="" class>扫码登录</a>
                </div>
                <div class="login-tab login-tab-r">
                    <a href="" class="checked">账户登录</a>
                </div>
                <div class="login-box" style="display: block; visibility: visible;"></div>


                <div class="form">
                    <form id="formlogin" method="post" action="${pageContext.request.contextPath}/cust/login">
                        <div class="item item-fore1">
                            <label for="loginname" class="login-label name-label"></label>
                            <input id="loginname" type="text" class="itxt username" name="username" tabindex="1"
                                   _input="true"
                                   autocomplete="off" value="" placeholder="请输入手机号或邮箱">
                            <span class="clear-btn"></span>
                        </div>
                        <div class="item item-fore2">
                            <label class="login-label pwd-label" for="nloginpwd"></label>
                            <input type="password" id="nloginpwd" name="password" class="itxt itxt-error password"
                                   tabindex="2"
                                   autocomplete="off" _input="true" placeholder="密码">
                            <span class="clear-btn"></span>
                        </div>
                        <div class="item item-fore4">
                            <div class="safe">
                                <c:if test="${empty loginMsg}">

                                <span>${loginMsg}
                                </span>
                                </c:if>

                                <c:if test="${!empty loginMsg}">
                                    <span class="msg-error"><b></b> ${loginMsg}

                                    </span>
                                </c:if>
                                <span class="forget-pw-safe">
											<a href="" class="" target="_blank"
                                               clstag="pageclick|keycount|login_pc_201804112|6">忘记密码</a>
										</span>
                            </div>
                        </div>
                        <div class="item item-fore5">
                            <div class="login-btn">
                                <input type="button" class="btn-img btn-entry loginBtn" style="border-style:none"
                                       id="loginsubmit" tabindex="6" value="登&nbsp;&nbsp;录"/><br/>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="coagent" id="kbCoagent">
                    <div class="regist-link"><a href="register.jsp"><b></b>立即注册</a></div>
                </div>
            </div>
        </div>
        <div class="login-banner" style="background-color: #5C37D2">
            <div class="w">
                <div id="banner-bg" class="i-inner" style="background: url(../images/login_bg.jpg) 0px 0px no-repeat;">

                </div>
            </div>
        </div>
    </div>
</div>
<div class="w">
    <div class="footer">
        <div class="links">
            <a rel="nofollow" target="_blank" href="//about.jd.com/">
                关于我们
            </a>
            |
            <a rel="nofollow" target="_blank" href="//www.jd.com/contact/">
                联系我们
            </a>
            |
            <a rel="nofollow" target="_blank" href="//zhaopin.jd.com/">
                人才招聘
            </a>
            |
            <a rel="nofollow" target="_blank" href="//lai.jd.com/">
                商家入驻
            </a>
            |
            <a rel="nofollow" target="_blank" href="//jzt.jd.com/">
                广告服务
            </a>
            |
            <a rel="nofollow" target="_blank" href="//app.jd.com/">
                手机京东
            </a>
            |
            <a target="_blank" href="//club.jd.com/links.aspx">
                友情链接
            </a>
            |
            <a target="_blank" href="//media.jd.com/">
                销售联盟
            </a>
            |
            <a href="//pro.jd.com/mall/active/3WA2zN8wkwc9fL9TxAJXHh5Nj79u/index.html" target="_blank">
                京东社区
            </a>
            |
            <a href="//gongyi.jd.com" target="_blank">
                京东公益
            </a>
            |
            <a target="_blank" href="//www.joybuy.com/" clstag="pageclick|keycount|20150112ABD|9">English Site</a>
        </div>
        <div class="copyright">
            Copyright&nbsp;©&nbsp;2004-2021&nbsp;&nbsp;树懒&nbsp;版权所有
        </div>
    </div>

</div>

<script src="../js/login.js"></script>
<script src="${pageContext.request.contextPath}/res/jquery/jquery-3.5.1.js"></script>
<script src="${pageContext.request.contextPath}/res/jsencrypt/bin/jsencrypt.min.js"></script>
<script>

    var PUBLIC_KEY = '';

    $(".loginBtn").click(function () {

        $.ajax({
            type: "GET",
            url: "${pageContext.request.contextPath}/publickey",
            dataType: 'json',
            success: function (result) {
                PUBLIC_KEY = result.data; //获取公钥

                var encrypt = new JSEncrypt();
                encrypt.setPublicKey('-----BEGIN PUBLIC KEY-----' + PUBLIC_KEY + '-----END PUBLIC KEY-----');

                // var username = $(".username").val();
                // var encryptusername = encrypt.encrypt(username);


                var password = $(".password").val();
                var encryptpassword = encrypt.encrypt(password);


                // console.log('公钥:%o', PUBLIC_KEY);
                // console.log('加密后数据:%o', encrypted);

                // $(".username").val(encryptusername);
                // $(".password").val(encryptpassword);

                var username = $(".username").val();


                $.post(
                    "${pageContext.request.contextPath}/cust/login",
                    { username: username, password: encryptpassword },
                    function (result) {
                        // $(".loginMessage").text(result.reason);
                        // console.log(result.code);
                        if (result.code==200){

                            var registerUrl = "http://localhost:8080/shulanmiaosha/customer/register.jsp";
                            if ((document.referrer||host + "")!=registerUrl){
                                location.href=document.referrer||host + "";
                            }else {
                                location.href="${pageContext.request.contextPath}/product/generalMerchandise.jsp";
                            }

                        }
                    },
                    'json'
                );
                // $("#formlogin").submit();

            }
        });
    });


</script>


</body>
</html>
